package com.cskaoyan.app.service.impl;

import com.cskaoyan.app.bean.bo.adminbo.AdminAdminBo;
import com.cskaoyan.app.bean.bo.adminbo.AdminListBo;
import com.cskaoyan.app.bean.common.CommonData;
import com.cskaoyan.app.bean.po.MarketAdmin;
import com.cskaoyan.app.bean.po.MarketLog;
import com.cskaoyan.app.bean.po.MarketLogExample;
import com.cskaoyan.app.bean.vo.adminVo.AdminListVo;
import com.cskaoyan.app.mapper.MarketLogMapper;
import com.cskaoyan.app.service.AdminLogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author kiggy
 * @since 2023/01/01 00:40
 */
@Service
public class AdminLogServiceImpl implements AdminLogService {

    @Autowired
    MarketLogMapper logMapper;

    /**
     * 从数据库中分页取出log
     * @return
     */
    @Override
    @Transactional
    public CommonData listLog(AdminListBo adminBo) {
        PageHelper.startPage(adminBo.getPage(),adminBo.getLimit());
        MarketLogExample marketLogExample = new MarketLogExample();
        MarketLogExample.Criteria criteria = marketLogExample.createCriteria();
        criteria.andDeletedEqualTo(false);
        marketLogExample.setOrderByClause(adminBo.getSort() + " " + adminBo.getOrder());
        List<MarketLog> marketAdmins = logMapper.selectByExample(marketLogExample);
        PageInfo<MarketLog> logPageInfo = new PageInfo<>(marketAdmins);
        CommonData<MarketLog> marketLogCommonData = CommonData.data(logPageInfo);
        return marketLogCommonData;
    }
}
